package com.example.myapplication.tack_04;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapplication.R;
import com.example.myapplication.tack_04.data.StopData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;


public class PageStop extends AppCompatActivity {
    private ImageView exit;
    private TextView parkName;
    private TextView address;
    private TextView distance;
    private TextView open;
    private TextView rates;
    private TextView vacancy;
    private TextView priceCaps;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_04_page_stop);
        Intent intent = getIntent();
        String id = intent.getStringExtra(Common.COMMON);
        init();
        exit_();
        getPage(id);
    }

    private void getPage(String id) {
        String url = "prod-api/api/park/lot/list?&pageNum="+id+"&pageSize=1";
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, StopData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                StopData stopData = (StopData) obj;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        pageAdapter(stopData);
                    }
                });
            }

            @Override
            public void onFailure(String msg) {

            }
        });

    }

    private void pageAdapter(StopData stopData) {
        parkName.setText(stopData.getRows().get(0).getParkName());
        address.setText(stopData.getRows().get(0).getAddress());
        distance.setText(stopData.getRows().get(0).getDistance());
        if("Y".equals(stopData.getRows().get(0).getOpen())){
            open.setText("是");
        }else if("N".equals(stopData.getRows().get(0).getOpen())){
            open.setText("否");
        }

        rates.setText(stopData.getRows().get(0).getRates()+"￥/小时");
        vacancy.setText(stopData.getRows().get(0).getVacancy());
        priceCaps.setText("每小时："+stopData.getRows().get(0).getRates()
                +"￥/小时 , 封顶价格："+ stopData.getRows().get(0).getPriceCaps()+"￥");
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PageStop.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        parkName = findViewById(R.id.parkName);
        address = findViewById(R.id.address);
        distance = findViewById(R.id.distance);
        open = findViewById(R.id.open);
        rates = findViewById(R.id.rates);
        vacancy = findViewById(R.id.vacancy);
        priceCaps = findViewById(R.id.priceCaps);
    }
}